package cn.yitun.chat.yitunserverimcore.general.main.push.contact;

import cn.yitun.chat.yituncommonmessage.push.PushMessage;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.dataentity.vo.contact.ContactRelationVo;
import cn.yitun.chat.yitunservercommonlib.enums.control.push.contact.ContactRelationPushMethodEnum;
import cn.yitun.chat.yitunserverimcore.bridge.net.WriteHandler;
import cn.yitun.chat.yitunserverimcore.general.common.util.PushMessageBuild;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 
 * Date 2019-01-27 21:43:21<br>
 * Description
 * 
 * @author yitun<br>
 * @since 1.1
 */
@Service
public class ContactRelationPush {
	//1.2.103
	final String action = ActionTypeConstant.CONTACT_RELATION_ACTION_PUSH;

	@Resource
	WriteHandler writeHandler;

	/**
	 * 添加
	 * @param key
	 * @param contactUserId
	 * @param userId
	 */
	public void pushAdd(Long key, Long contactUserId, Long userId) {
		String method = ContactRelationPushMethodEnum.ADD_PUSH.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("contactUserId", contactUserId);
		writeHandler.push(userId, message);
	}

	/**
	 * 更新备注
	 * @param key
	 * @param contactUserId
	 * @param remark
	 * @param userId
	 */
	public void pushUpdateRemark(Long key, Long contactUserId, String remark, Long userId) {
		String method = ContactRelationPushMethodEnum.UPDATE_REMARK_PUSH.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("contactUserId", contactUserId);
		message.bodyPut("remark", remark);
		writeHandler.push(userId, message);
	}

	/**
	 * 移动到分组
	 * @param key
	 * @param contactUserIds
	 * @param categoryId
	 * @param userId
	 */
	public void pushMoveCategory(Long key, List<Long> contactUserIds, Long categoryId, Long userId) {
		String method = ContactRelationPushMethodEnum.MOVE_CATEGORY_PUSH.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("contactUserIds", contactUserIds);
		message.bodyPut("categoryId", categoryId);
		writeHandler.push(userId, message);
	}

	/**
	 * 删除
	 * @param key
	 * @param contactUserId
	 * @param userId
	 */
	public void pushDelete(Long key, Long contactUserId, Long userId) {
		String method = ContactRelationPushMethodEnum.REMOVE_PUSH.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("contactUserId", contactUserId);
		writeHandler.push(userId, message);
	}

	/**
	 * 冻结
	 * @param key
	 * @param contactUserId
	 * @param isBlocked
	 * @param userId
	 */
	public void pushUpdateBlocked(Long key, Long contactUserId, String isBlocked, Long userId) {
		String method = ContactRelationPushMethodEnum.UPDATE_BLOCKED_PUSH.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("contactUserId", contactUserId);
		message.bodyPut("isBlocked", isBlocked);
		writeHandler.push(userId, message);
	}

	/**
	 * 推送列表
	 * @param key
	 * @param userId
	 */
	public void pushSetList(Long key, List<ContactRelationVo> list, Long userId) {
		String method = ContactRelationPushMethodEnum.SET_LIST_PUSH.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("list", list);
		writeHandler.push(userId, message);
	}
}
